var ZKIDROnlineUrl = "http://127.0.0.1:24010/ZKIDROnline";

/**
*指纹图像的原始数据
*/
function getRawBase64()
{
	$.ajax( {
		type : "GET",
		url : ZKIDROnlineUrl+"/IDFP?OP-DEV=1&CMD-URL=1",
		dataType : "json",
		async: false,
		//timeout:1000,
		success : function(result) 
		{
			var ret = result.ret;
			if(ret == 0)
			{
				var rawBase64 = result.data.rawBase64;
				var jpgBase64 = result.data.jpgBase64;
				$("#rawBase64").val(rawBase64);
				document.getElementById("rawBase64Img").src="data:image/png;base64,"+jpgBase64;
			}
			else
			{
				alert("操作失败！错误码="+ret);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) 
		{
			alert("操作失败！");
	    }
	});
}

/**
*指纹模板数据
*/
function getFeature(obj)
{
	$.ajax( {
		type : "GET",
		url : ZKIDROnlineUrl+"/IDFP?OP-DEV=1&CMD-URL=2",
		dataType : "json",
		async: false,
		success : function(result) 
		{
			var ret = result.ret;
			if(ret == 0)
			{
				var feature = result.data.feature;
				var jpgBase64 = result.data.jpgBase64;
				$('#'+obj).val(feature);
				document.getElementById("rawBase64Img").src="data:image/png;base64,"+jpgBase64;
			}
			else
			{
				alert("操作失败！错误码="+ret);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown)
		{
			alert("操作失败！");
	    }
	});
}

function transferredMeaning(src)
{
	src = src.replace(/\+/g, "%2B");
	src = src.replace(/&/g, "%26");
	src = src.replace(/\%/g, "%25");
	src = src.replace(/\//g, "%2F");
	src = src.replace(/\?/g, "%3F");
	src = src.replace(/\#/g, "%23");
	src = src.replace(/\=/g, "%3D");
	src = src.replace(/\ /g, "%20");
	return src;
}

/**
*指纹图像比对指纹模板
*/
function rawComparisionFeature()
{
	var rawBase64 = $("#rawBase64").val();
	var feature = $("#feature1").val();
	$.ajax( {
		type : "POST",
		url : ZKIDROnlineUrl+"/IDFP?OP-DEV=1&CMD-URL=3",
		data : JSON.stringify({
	        'rawBase64' : rawBase64,
	        'feature' : feature
	    }),
		dataType : "json",
		async: false,
		success : function(result)
		{
			var ret = result.ret;
			if(ret == 0)
			{
				var score = result.data.score;
				if(score>=55)
				{
					alert("比对成功!");
				}
				else
				{
					alert("比对阈值为"+score+"，比对失败！");
				}
			}
			else
			{
				alert("操作失败！错误码="+ret);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) 
		{
			alert("操作失败！");
	    }
	});
}

/**
*指纹模板比对指纹模板
*/
function featureComparisionFeature()
{
	var regFeature = $("#feature1").val();
	var verFeature = $("#feature2").val();
	$.ajax( {
		type : "POST",
		url : ZKIDROnlineUrl+"/IDFP?OP-DEV=1&CMD-URL=4",
		data : JSON.stringify({
	        'regFeature' : regFeature,
	        'verFeature' : verFeature
	    }),
		dataType : "json",
		async: false,
		success : function(result) 
		{
			var ret = result.ret;
			if(ret == 0)
			{
				var score = result.data.score;
				if(score>=55)
				{
					alert("比对成功!");
				}
				else
				{
					alert("比对阈值为"+score+"，比对失败！");
				}
			}
			else
			{
				alert("操作失败！错误码="+ret);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) 
		{
			alert("操作失败！");
	    }
	});
}

function clearData()
{
	$("#rawBase64").val("");
	$("#feature1").val("");
	$("#feature2").val("");
}